/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

/**
 *
 * @author Miguel
 */
public class ValidarRutDAO {
    
    public static boolean validarRut(String rut) {  

boolean validacion = false;  
    try {  
  
            rut = rut.replace(".", "");  
            rut = rut.replace("-", "");  
            int rutAux = Integer.parseInt(rut.substring(0, rut.length() - 1));  
  
            char dv = rut.charAt(rut.length() - 1);  
  
            int m = 0, s = 1;  
            for (; rutAux != 0; rutAux /= 10) {  
            s = (s + rutAux % 10 * (9 - m++ % 6)) % 11;  
            }  
            if (dv == (char) (s != 0 ? s + 47 : 75)) 
            {  
            validacion = true;
            } 
            
            
        } 
    catch (java.lang.NumberFormatException e) 
    {  
        e.getMessage();
    }   
    catch (Exception e) 
    {  
        e.getMessage();
    }  
    return validacion;  
}  
}
